﻿using itk.simple;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ImageDomain.Utils;
public class LabelSplitUtil
{
    public static Image ExtractLabel(Image image, int label)
    {
        var thresholdFilter = new ThresholdImageFilter();
        thresholdFilter.SetLower(label);
        thresholdFilter.SetUpper(label);
        thresholdFilter.SetOutsideValue(0);

        // 应用阈值过滤器
        var labelImage = thresholdFilter.Execute(image);

        // 将标签的值设置为1
        var binaryThresholdFilter = new BinaryThresholdImageFilter();
        binaryThresholdFilter.SetLowerThreshold(label);
        binaryThresholdFilter.SetUpperThreshold(label);
        binaryThresholdFilter.SetInsideValue(1);
        binaryThresholdFilter.SetOutsideValue(0);

        return binaryThresholdFilter.Execute(labelImage);
    }
}
